package com.yanqu.road.server.cmd.activity.langyabang;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LangYaBangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.langyabang.LangYaBangModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_LANG_YA_BANG_CASE_GAME_START,desc = "玩家开始或解锁新金陵风云游戏案件")
public class LangYaBangStartCaseGameCmd extends AbstractCommand {
    private int activityId;
    private int chooseCase;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        LangYaBangProto.LangYaBangCaseGameStartReqMsg reqMsg = LangYaBangProto.LangYaBangCaseGameStartReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        chooseCase = reqMsg.getCaseId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(LangYaBangModule.class).openLangYaBangCaseGame(activityId,chooseCase);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            LangYaBangProto.LangYaBangCaseGameStartRespMsg.Builder builder = LangYaBangProto.LangYaBangCaseGameStartRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_LANG_YA_BANG_CASE_GAME_START,builder);
        }
    }
}
